<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/product.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a href="<?php echo $cancel; ?>" class="button"><?php echo $button_cancel; ?></a></div>
    </div>
    <div class="content">
      <div id="tabs" class="htabs">
		<a href="#tab-general"><?php echo $tab_general; ?></a>
		<a href="#tab-data"><?php echo $tab_data; ?></a>
		<a href="#tab-purchase-price"><?php echo $tab_purchase_price; ?></a>
		<a href="#tab-sale-price"><?php echo $tab_sale_price; ?></a>
	  </div>
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
        <div id="tab-general">
          <div id="languages" class="htabs">
            <?php foreach ($languages as $language) { ?>
            <a href="#language<?php echo $language['language_id']; ?>"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> <?php echo $language['name']; ?></a>
            <?php } ?>
          </div>
          <?php foreach ($languages as $language) { ?>
          <div id="language<?php echo $language['language_id']; ?>">
            <table class="form">
              <tr>
                <td><span class="required">*</span> <?php echo $entry_name; ?></td>
                <td><input type="text" name="item_description[<?php echo $language['language_id']; ?>][name]" size="100" value="<?php echo isset($item_description[$language['language_id']]) ? $item_description[$language['language_id']]['name'] : ''; ?>" />
                  <?php if (isset($error_name[$language['language_id']])) { ?>
                  <span class="error"><?php echo $error_name[$language['language_id']]; ?></span>
                  <?php } ?></td>
              </tr>
              <tr>
                <td><?php echo $entry_description; ?></td>
                <td><textarea name="item_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($item_description[$language['language_id']]) ? $item_description[$language['language_id']]['description'] : ''; ?></textarea></td>
              </tr>
            </table>
          </div>
          <?php } ?>
        </div>
        <div id="tab-data">
          <table class="form">
            <tr>
              <td><span class="required">*</span> <?php echo $entry_purchase_code; ?></td>
              <td><input type="text" name="purchase_code" value="<?php echo $purchase_code; ?>" />
                <?php if ($error_purchase_code) { ?>
                <span class="error"><?php echo $error_purchase_code; ?></span>
                <?php } ?></td>
            </tr>
            <tr>
              <td><?php echo $entry_sale_code; ?></td>
              <td><input type="text" name="sale_code" value="<?php echo $sale_code; ?>" /></td>
            </tr>
            <tr>
              <td><?php echo $entry_image; ?></td>
              <td><div class="image"><img src="<?php echo $thumb; ?>" alt="" id="thumb" /><br />
                  <input type="hidden" name="image" value="<?php echo $image; ?>" id="image" />
                  <a onclick="image_upload('image', 'thumb');"><?php echo $text_browse; ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a onclick="$('#thumb').attr('src', '<?php echo $no_image; ?>'); $('#image').attr('value', '');"><?php echo $text_clear; ?></a></div></td>
            </tr>
            <tr>
              <td><?php echo $entry_group; ?></td>
              <td><select name="group_id">
                  <?php foreach ($groups as $group) { ?>
                  <?php if ($group['group_id'] == $group_id) { ?>
                  <option value="<?php echo $group['group_id']; ?>" selected="selected"><?php echo $group['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $group['group_id']; ?>"><?php echo $group['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select></td>
            </tr>
            <tr>
              <td><?php echo $entry_unit; ?></td>
              <td><input type="text" name="unit" value="<?php $unit; ?>" /></td>
            </tr>
            <tr>
              <td><?php echo $entry_status; ?></td>
              <td><select name="status">
                  <?php if ($status) { ?>
                  <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                  <option value="0"><?php echo $text_disabled; ?></option>
                  <?php } else { ?>
                  <option value="1"><?php echo $text_enabled; ?></option>
                  <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                  <?php } ?>
                </select></td>
            </tr>
          </table>
        </div>
        <div id="tab-purchase-price">
          <table class="list" id="purchase">
            <thead>
              <tr>
                <td class="left"><?php echo $column_supplier; ?></td>
                <td class="left"><?php echo $column_purchase_price; ?></td>
                <td>&nbsp;</td>
              </tr>
            </thead>
            <?php $purchase_price_row = 0; ?>
            <?php foreach ($purchase_prices as $purchase_price) { ?>
            <tbody id="purchase-price-row<?php echo $purchase_price_row; ?>">
              <tr>
                <td class="left"><select name="purchase_price[<?php echo $purchase_price_row; ?>][supplier_id]">
                    <?php foreach ($suppliers as $supplier) { ?>

                      <?php if ($supplier['supplier_id'] == $purchase_price['supplier_id']) { ?>
                      <option value="<?php echo $supplier['supplier_id']; ?>" selected="selected"><?php echo $supplier['name']; ?></option>
                      <?php } else { ?>
                      <option value="<?php echo $supplier['supplier_id']; ?>" ><?php echo $supplier['name']; ?></option>
                      <?php } ?>
                    <?php } ?>
                  </select>
                <td class="left"><input type="text" name="purchase_price[<?php echo $purchase_price_row; ?>][price]" value="<?php echo $purchase_price['price']; ?>" /></td>
                <td class="left"><a onclick="$('#purchase-price-row<?php echo $purchase_price_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
              </tr>
            </tbody>
            <?php $purchase_price_row++; ?>
            <?php } ?>
            <tfoot>
              <tr>
                <td colspan="2"></td>
                <td class="left"><a onclick="addPurchasePrice();" class="button"><?php echo $button_add_purchase; ?></a></td>
              </tr>
            </tfoot>
          </table>
        </div>
        <div id="tab-sale-price">
          <table id="sale-price" class="list">
            <thead>
              <tr>
                <td class="left"><?php echo $column_customer_group; ?></td>
                <td class="left"><?php echo $column_quantity; ?></td>
                <td class="left"><?php echo $column_sale_price; ?></td>
                <td>&nbsp;</td>
              </tr>
            </thead>
            <?php $sale_price_row = 0; ?>
            <?php foreach ($item_sale_prices as $item_sale_price) { ?>
            <tbody id="sale-price-row<?php echo $sale_price_row; ?>">
              <tr>
                <td class="left"><select name="item_sale_price[<?php echo $sale_price_row; ?>][type_id]">
                    <?php foreach ($sale_types as $sale_type) { ?>
                    <?php if ($sale_type['type_id'] == $item_sale_price['type_id']) { ?>
                    <option value="<?php echo $sale_type['type_id']; ?>" selected="selected"><?php echo $sale_type['name']; ?></option>
                    <?php } else { ?>
                    <option value="<?php echo $sale_type['type_id']; ?>"><?php echo $sale_type['name']; ?></option>
                    <?php } ?>
                    <?php } ?>
                  </select></td>
                <td class="left"><input type="text" name="item_sale_price[<?php echo $sale_price_row; ?>][quantity]" value="<?php echo $item_sale_price['quantity']; ?>" size="2" /></td>
                <td class="left"><input type="text" name="item_sale_price[<?php echo $sale_price_row; ?>][price]" value="<?php echo $item_sale_price['price']; ?>" /></td>
                <td class="left"><a onclick="$('#sale-price-row<?php echo $sale_price_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
              </tr>
            </tbody>
            <?php $sale_price_row++; ?>
            <?php } ?>
            <tfoot>
              <tr>
                <td colspan="3"></td>
                <td class="left"><a onclick="addSalePrice();" class="button"><?php echo $button_add_sale; ?></a></td>
              </tr>
            </tfoot>
          </table>
        </div>
      </form>
    </div>
  </div>
</div>
<script type="text/javascript" src="view/javascript/ckeditor/ckeditor.js"></script> 
<script type="text/javascript"><!--
<?php foreach ($languages as $language) { ?>
CKEDITOR.replace('description<?php echo $language['language_id']; ?>', {
	filebrowserBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserImageBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserFlashBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserImageUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserFlashUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>'
});
<?php } ?>
//--></script> 
<script type="text/javascript"><!--
function image_upload(field, thumb) {
	$('#dialog').remove();
	
	$('#content').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="index.php?route=common/filemanager&token=<?php echo $token; ?>&field=' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
	
	$('#dialog').dialog({
		title: '<?php echo $text_image_manager; ?>',
		close: function (event, ui) {
			if ($('#' + field).attr('value')) {
				$.ajax({
					url: 'index.php?route=common/filemanager/image&token=<?php echo $token; ?>&image=' + encodeURIComponent($('#' + field).attr('value')),
					dataType: 'text',
					success: function(text) {
						$('#' + thumb).replaceWith('<img src="' + text + '" alt="" id="' + thumb + '" />');
					}
				});
			}
		},	
		bgiframe: false,
		width: 800,
		height: 400,
		resizable: false,
		modal: false
	});
};
//--></script> 
<script type="text/javascript"><!--
var image_row = <?php echo $image_row; ?>;

function addImage() {
    html  = '<tbody id="image-row' + image_row + '">';
	html += '  <tr>';
	html += '    <td class="left"><div class="image"><img src="<?php echo $no_image; ?>" alt="" id="thumb' + image_row + '" /><input type="hidden" name="product_image[' + image_row + '][image]" value="" id="image' + image_row + '" /><br /><a onclick="image_upload(\'image' + image_row + '\', \'thumb' + image_row + '\');"><?php echo $text_browse; ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a onclick="$(\'#thumb' + image_row + '\').attr(\'src\', \'<?php echo $no_image; ?>\'); $(\'#image' + image_row + '\').attr(\'value\', \'\');"><?php echo $text_clear; ?></a></div></td>';
	html += '    <td class="right"><input type="text" name="product_image[' + image_row + '][sort_order]" value="" size="2" /></td>';
	html += '    <td class="left"><a onclick="$(\'#image-row' + image_row  + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
	html += '  </tr>';
	html += '</tbody>';
	
	$('#images tfoot').before(html);
	
	image_row++;
}
//--></script> 
<script type="text/javascript" src="view/javascript/jquery/ui/jquery-ui-timepicker-addon.js"></script> 
<script type="text/javascript"><!--
$('.date').datepicker({dateFormat: 'yy-mm-dd'});
$('.datetime').datetimepicker({
	dateFormat: 'yy-mm-dd',
	timeFormat: 'h:m'
});
$('.time').timepicker({timeFormat: 'h:m'});
//--></script> 
<script type="text/javascript"><!--
$('#tabs a').tabs(); 
$('#languages a').tabs(); 
$('#vtab-option a').tabs();
//--></script> 

<script type="text/javascript"><!--
var sale_price_row = <?php echo $sale_price_row; ?>;

function addSalePrice() {
  html  = '<tbody id="sale-price-row' + sale_price_row + '">';
  html += '  <tr>'; 
    html += '    <td class="left"><select name="item_sale_price[' + sale_price_row + '][type_id]">';
    <?php foreach ($sale_types as $sale_type) { ?>
    html += '      <option value="<?php echo $sale_type['type_id']; ?>"><?php echo $sale_type['name']; ?></option>';
    <?php } ?>
    html += '    </select></td>';   
    html += '    <td class="left"><input type="text" name="item_sale_price[' + sale_price_row + '][quantity]" value="" size="5" /></td>';
    html += '    <td class="left"><input type="text" name="item_sale_price[' + sale_price_row + '][price]" value="" size="20" /></td>';
   html += '    <td class="left"><a onclick="$(\'#sale-price-row' + sale_price_row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
  html += '  </tr>';  
    html += '</tbody>';
  
  $('#sale-price tfoot').before(html);
  
  sale_price_row++;
}
//--></script> 

<script type="text/javascript"><!--
var purchase_price_row = <?php echo $purchase_price_row; ?>;

function addPurchasePrice() {
  html  = '<tbody id="purchase-price-row' + purchase_price_row + '">';
  html += '  <tr>'; 
    html += '    <td class="left"><select name="purchase_price[' + purchase_price_row + '][supplier_id]">';
    <?php foreach ($suppliers as $supplier) { ?>
    html += '      <option value="<?php echo $supplier['supplier_id']; ?>"><?php echo $supplier['name']; ?></option>';
    <?php } ?>
    html += '    </select></td>';   
    html += '    <td class="left"><input type="text" name="purchase_price[' + purchase_price_row + '][price]" value="" size="20" /></td>';
   html += '    <td class="left"><a onclick="$(\'#purchase-price-row' + purchase_price_row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
  html += '  </tr>';  
    html += '</tbody>';
  
  $('#purchase tfoot').before(html);
  
  purchase_price_row++;
}
//--></script> 
<?php echo $footer; ?>